package com.psp.bu.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.bu.controller.res.*;
import com.psp.bu.controller.res.bean.*;
import com.psp.bu.controller.springmvc.req.*;

/**
 * 需求登记记录-相关接口
 **/
@Controller
@RequestMapping(value = "/bu/demand", produces = "application/json")
public class SDemandController {
	@Autowired
	com.psp.bu.controller.DemandController demandController;

	/**
	 * 获取合作商家列表
	 **/
	@RequestMapping("/v1/list")
	@ResponseBody
	public ListResult<RDemandBean> list(@Validated GetDemandListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RDemandBean> res = new ListResult<RDemandBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return demandController.list(param, request, response);
	}

	/**
	 * 处理合作
	 **/
	@RequestMapping("/v1/handle")
	@ResponseBody
	public BaseResult handle(@Validated HandleDemandParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return demandController.handle(param, request, response);
	}
}
